# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
from apps.pms.models import Version, Product
from apps.sys.models import User


class VersionResouces(CustomerModelResource):
    product = Field(attribute="product", widget=ForeignKeyWidget(Product, field="name"))
    parent = Field(attribute="parent", widget=ForeignKeyWidget(Version, field="name"))
    owner = Field(attribute="owner", widget=ForeignKeyWidget(User, field="username"))

    class Meta:
        model = Version
        fields = ("name", "product", "parent", "source", "download", "owner", "remark")
        import_id_fields = ("product", "name")
        export_order = fields
